<?php

namespace App\Admin\Actions\GoldProductAction;

use App\Models\GoldRound;
use Illuminate\Http\Request;
use App\Supports\Withdraw\Withdrawer;
use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;
use App\Services\BatchMoveGoldProducts\BatchMoveGoldProducts;

class BatchMove extends BatchAction
{
	public $name = '批量转移场次';

	public function handle(Collection $collection, Request $request)
	{
		if ($collection->count() > 100) {
			return $this->response()->error('每次最多处理100条');
		}

		$rid = $request->get('rid');

		app(BatchMoveGoldProducts::class, [
			'collection' => $collection,
			'rid' => $rid
		])->move();

		return $this->response()->success('批量转场已提交')->refresh();
	}

	public function form()
	{
		$this->select('rid', '金店场次')
			->options(GoldRound::all()->pluck('title', 'id'))
			->rules('required');
	}
}
